package com.javacode2018.demo5;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.List;

public class Demo5Test {
    UserService userService;

    public void before() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig5.class);
        this.userService = context.getBean(UserService.class);
    }

    @Test
    public void test1() {
        this.userService.insert();
    }

    @Test
    public void test2() {
        List<User> list = this.userService.list();
        System.out.println(list);
    }

    @Test
    public void test3() {
        String name = this.userService.name(1);
        System.out.println(name);
    }

    public static void test4() throws Error {
        throw new NoClassDefFoundError("xxx");
    }

    @Test
    public void test5() {
        try {
            test4();
        } catch (Error error) {
            error.printStackTrace();
        }
        System.out.println("哈哈");
    }
}
